package mfuny.ggongal.admin;

import javax.servlet.http.HttpSession;

import mfuny.ggongal.admin.ad.AdDao;
import mfuny.ggongal.admin.ad.AdGgongService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class AdGgongController {
	AdGgongService ad;
	AdDao adDao;
	
	public AdGgongController() throws Exception {
		ad = new AdGgongService();
		adDao = new AdDao();
	}
	
	@RequestMapping("/regGgong1.ga")
	public ModelAndView regGgong1() throws Exception {
		return ad.regGgong1( );
	}
	
	@RequestMapping("/regGgong2.ga")
	public ModelAndView regGgong2( @ModelAttribute AdDao adDao, String pageNum, HttpSession session ) throws Exception {
		if ( adDao.getCo_id( ) != null && !adDao.getCo_id( ).equals( "" ) ) { 
			session.setAttribute( "adDao", adDao ); 
		}
		return ad.regGgong2( pageNum );
	}
	
	@RequestMapping("/regGgong3.ga")
	public ModelAndView regGgong3( int game_no, HttpSession session ) throws Exception {
		adDao = (AdDao)session.getAttribute( "adDao" );
		adDao.setGame_no( game_no );
		session.setAttribute( "adDao", adDao );
		return ad.regGgong3( game_no );
	}
	
	@RequestMapping("/regGgong.ga")
	public ModelAndView regGgong( String mission, HttpSession session ) throws Exception {
		adDao = (AdDao)session.getAttribute( "adDao" );
		adDao.setMission( mission );
		session.removeAttribute( "adDao" );
		ad.regGgong( adDao );
		return ad.getGgong( );
	}
	
	@RequestMapping("/getRegistedDays.ga")
	public ModelAndView getRegistedDays( String year, String month ) throws Exception {
		return ad.getRegistedDays( year, month );
	}
	
	@RequestMapping("/selectAdvPopup.ga")
	public ModelAndView selectAdvPopup() throws Exception {
		return ad.selectAdvPopup( );
	}
	
	@RequestMapping("/selectAdPopup.ga")
	public ModelAndView selectAdPopup( String co_id ) throws Exception {
		return ad.selectAdPopup( co_id );
	}
	
	@RequestMapping("/getGgong.ga")
	public ModelAndView getGgong() throws Exception {
		return ad.getGgong( );
	}
	
	@RequestMapping("/registedListPopup.ga")
	public ModelAndView registedListPopup( String year, String month, String day ) throws Exception {
		return ad.registedListPopup( year, month, day );
	}
	
	@RequestMapping("/detailGgongGame.ga")
	public ModelAndView detailGgongGame(int ad_no) throws Exception {
		return ad.detailGgongGame(ad_no);
	}
	
	@RequestMapping("/deleteGGame.ga")
	public ModelAndView deleteGGame(int ad_no) throws Exception {
		return ad.deleteGGame(ad_no);
	}
}
